const judge = require('../model/judgeModel.js')
const { judgeTime } = require('../tool/tool.js')

async function add(ctx) {
    let date = await judgeTime()
    let data = {
        uid: ctx.user.id,
        content: ctx.request.body.content,
        gid: ctx.request.body.gid,
        o_gid: ctx.request.body.o_gid,
        star: ctx.request.body.star,
        photo: ctx.request.body.photo,
        judgetime: date,
    }
    let res = await judge.add(data)
    ctx.body = res
}

async function list(ctx) {

    let gid = ctx.request.query.gid;
    let uid = ctx.user.id;
    let result = await judge.list({ gid, uid });

    if (result.total) {
        ctx.body = { code: 1, msg: '', data: result }
    } else {
        ctx.body = { code: 0, msg: '暂无数据', data: '' }
    }
}

async function del(ctx) {
    let data = {
        uid: ctx.user.id,
        id: ctx.request.query.id
    };
    let res = await judge.del(data);

    ctx.body = res

}



module.exports = { add, list, del }